package com.viethp.mt.activities;

import com.viethp.mt.activities.R;
import com.viethp.mt.common.CommonHelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class ASplashScreen extends Activity {

	protected int _splashTime = 500;
	private Thread splashTread;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.a_splash_screen);

		showSplash();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			synchronized (splashTread) {
				splashTread.notifyAll();
			}
		}
		return true;
	}

	public void showSplash() {
		splashTread = new Thread() {
			@Override
			public void run() {
				try {
					synchronized (this) {

						// wait 5 sec
						wait(_splashTime);
					}

				} catch (InterruptedException e) {
				} finally {
					if (CommonHelper.getLoginMethod(getApplicationContext()) != 0) {
						Intent amain = new Intent(getApplicationContext(),
								AMain.class);
						// amain.putExtra("user_id",
						// String.valueOf(CommonHelper.getUserLogin(getApplicationContext()).getId()));
						startActivity(amain);
					} else {
						Intent i = new Intent(getBaseContext(),
								ALoginScreen.class);
						startActivity(i);
					}
					finish();

					ASplashScreen.this.overridePendingTransition(R.anim.appear,
							R.anim.disappear);

				}
			}
		};

		splashTread.start();
	}

}